package pro.cherish.knowledgemqrocketmq.test01;

/**
 * @author 创建人：cherish
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2019-10-29 cherish 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：MqProducer
 * @Description 功能说明：
 * <p>
 * TODO
 * </p>
 * **********************************************************************
 * @date 创建日期： 2019-10-29 cherish
 */

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;


/**
 * @author：duomu
 * @date：2017/8/4 18:09
 */
@Slf4j
public class MqProducer {

    public static void main(String[] args) {
        DefaultMQProducer producer = new DefaultMQProducer("Producer");
        producer.setNamesrvAddr("127.0.0.1:9876");
        try {
            producer.start();
            log.info("producer启动成功");
            for (int i = 0; i < 5; i++) {
                Message msg = new Message("TopicA", "tagA", "OrderID188", "Hello world".getBytes());
                SendResult result = producer.send(msg);
                log.info("id：" + result.getMsgId() + " result:" + result.getSendStatus());
            }
        } catch (Exception e) {
            log.error("发送消息失败，Exception error：" + e);
        } finally {
            producer.shutdown();
        }
    }
}

